﻿using AutoMapper;
using HslCommunication;
using System.Runtime.CompilerServices;

namespace DA.Utility.Mapper
{
    public static class AutoMap
    {
        private static IMapper Mapper;
        static AutoMap()
        {
            Mapper = new MapperConfiguration(c =>
            {
                c.CreateMap(typeof(OperateResult<bool>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<float>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<double>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<short>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<ushort>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<int>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<uint>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<long>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<ulong>), typeof(OperateResult<object>));
                c.CreateMap(typeof(OperateResult<string>), typeof(OperateResult<object>));
            }).CreateMapper();
        }
        public static T MapTo<T>(this object obj)
        {
            return Mapper.Map<T>(obj);
        }
    }
}
